function [sel] = selector(arg)
%
%
sel = [];
if(nargin == 0)
   hfig = findobj('Tag', 'Datac_Select');
   if(isempty(hfig))
      hfig = figure('Tag', 'Datac_Select');
   end;
   
   figure(hfig);
   clf;
   c = datac('control');
   p = {c.protocol};
   u = unique(p);
   uicontrol('units', 'normalized', ...
      'position', [0.1 0.7 0.3 0.2], ...
      'style', 'listbox',...
      'min', 1, ...
      'max', length(u), ...
      'String', u', ...
      'callback', 'selector(1)', ...
      'Tag', 'Datac_Select_list');
   
   p = {c.E_C};
   for i = 1:length(p)
      if(isnumeric(p{i}))
         p{i} = sprintf('%d',p{i});
      end;
   end;
   u = unique(p);
   uicontrol('units', 'normalized', ...
      'position', [0.1 0.45 0.3 0.2], ...
      'style', 'listbox',...
      'min', 1, ...
      'max', length(u), ...
      'String', u', ...
      'callback', 'selector(2)', ...
      'Tag', 'Datac_Select_EC');
   
else
   ptr = [];
   switch(arg)
   case 1
      hl = findobj('Tag', 'Datac_Select_list');
   if(isempty(hl))
      return;
   end;
   choice = get(hl, 'Value');
   u = get(hl, 'String');
   seln = u{choice(1)};
   c = datac('control');
   p = {c.protocol};
   ptr = strmatch(seln, p);
case 2
         hl = findobj('Tag', 'Datac_Select_EC');
   if(isempty(hl))
      return;
   end;
   choice = get(hl, 'Value');
   u = get(hl, 'String');
   seln = u{choice(1)};
   c = datac('control');
   p = {c.E_C};
   for i = 1:length(p)
      if(isnumeric(p{i}))
         p{i} = sprintf('%d',p{i}); % convert numbers to text.
      end;
   end;
   ptr = strmatch(seln, p);
   
otherwise
end;

% set the selection on the window. Analysis pays attention to this to do batch runs.   
   hCtl=findobj('Tag', 'CTL'); % first get the selection number
   set(hCtl, 'Value', ptr);
end;
